Music Object Extension - Dynamic

  Contents

About This Extension

Sound and music on a Web site is a double-edged sword. Flashy in a similar way to animated GIFs, Shockwave movies, Java banners, etc., music can really grab a surfer's attention. At the same time, however, music that is upfront and attention-grabbing can also fast become annoying if it is always the same each time the surfer visits your site.

Randomization is a key weapon in the war against tedious and unchanging Web sites. Adding some freshness through dynamically selected music can go a long way towards making Web sites hold up to repeat visits and still leave the Web surfer feeling engaged and interested.

Pages that never sound repetitive will invite repeat visitors who will return with the confidence that their ears will be treated to different sounding pages each time. The methods offered by this Music Object extension will help you author pages with this level of musical "freshness" that doesn't easily get stale and tiresome to the end-user.

What's New in the Latest Version

There is a dedicated version history for this extension, where you will be able to find out about the new features and possible issues with the most recent version. The version history for this extension is independent of the version history for the core Music Object API.

Getting This Extension

To get the "music-object-x-dynamic.js" JavaScript file that implements this extension, simply right-click on this link (click-and-hold for Mac users). Then, from the menu that pops up, select the 'Save Link As...' or 'Save Target As...' option and save the file as "music-object-x-dynamic.js" into an appropriate folder of the local copy of your Web site.

In case you have problems saving the file using the above link, the "music-object-x-dynamic.js" file can also be found inside the documentation's "javascript" folder, along with the "music-object.js" file.

Dependencies

In order to use this extension, the following JavaScript file(s) must first be sourced in...

For more information on using extensions, consult the section About Music Object Extensions.

Reference

 Name   Short Description 
Instance Methods
playRandomNote Plays a randomized musical note within specified limits of pitch, velocity, duration, volume, and pan.
Static Methods
Music.extractGroup Generates an array, representing a subgroup of a specified source array.
Music.groovoidGroup Generates an array of Groovoid names, determined by a specified group prefix parameter.
Music.kwiklistToArray Generates an array containing all the elements represented by the specified Kwiklist shorthand.
Music.random Generates a random integer within a specified range.
Music.randomFromGroup Randomly selects an item out of the specified group, as determined by a specified group prefix parameter.
Music.randomFromList Randomly selects an item out of a specified list of items.
Music.randomGroovoid Randomly selects a Groovoid within a specified Groovoid group.
Objects
Music.Shuffler An object that generates integer numbers that are seemingly more random, using a "shuffling" algorithm.
Static Properties
Music.groovoids An array representing all the Groovoids contained in the Beatnik Player soundbank.

Instance Methods

 playRandomNote

 
 CATEGORY   Instance Method 
 MODULE   Music Object Extension - Dynamic 
 Min. Player Version   1.0.0 
 File Types Supported   RMF, MIDI 
 

The playRandomNote method lets you play a randomized musical note within specified limits of pitch, velocity, duration, volume, and pan.

SYNTAX    playRandomNote (
    MidiChannel1to16 ,
    BankNumber0to2 ,
    ProgramNumber0to255 ,
    MinNoteNumber0to127orNoteNameSTR ,
    MaxNoteNumber0to127orNoteNameSTR ,
    MinVelocity0to127 ,
    MaxVelocity0to127 ,
    MinNoteDurationMsINT ,
    MaxNoteDurationMsINT ,
    MinVolumeControllerValue0to127 ,
    MaxVolumeControllerValue0to127 ,
    PanLeftControllerValue0to127 ,
    PanRightControllerValue0to127
)

SPECIAL VALUES
VARIATIONS
NOTES
Static Methods

 Music.extractGroup

 
 CATEGORY   Static Method 
 MODULE   Music Object Extension - Dynamic 
 Min. Player Version   n/a 
 

The Music.extractGroup static method generates an array, representing a subgroup of a specified source array.

SYNTAX    Music.extractGroup ( SourceARRAY , GroupPrefixSTR )

RETURN VALUE    StringARRAY

The Music.extractGroup static method generates an array, representing a subgroup of the source array specified by the SourceARRAY parameter. The source array should only contain string elements, and the GroupPrefixSTR parameter will be used to determine which elements of the source array make it into the resulting subgroup. Consider the following example...

SourceARRAY GroupPrefixSTR ResultARRAY
able-to-funk.wav
functional-music.mid
funk-monster.rmf
funk-u-mutha-funka.wav
funkadelic.rmf
funky-chicken.mid
get-down-and-funk.wav
living-funkster.mid
turn-up-the-funk.rmf
funk funk-monster.rmf
funk-u-mutha-funka.wav
funkadelic.rmf
funky-chicken.mid

In the source array, there are several elements containing the text "funk", but only some of those are prefixed with "funk". In this case, using the text "funk" for the GroupPrefixSTR parameter will return an array containing only those elements that are prefixed with "funk", as shown to the right of the diagram above.

SPECIAL VALUES
VARIATIONS
 Music.groovoidGroup

 
 CATEGORY   Static Method 
 MODULE   Music Object Extension - Dynamic 
 Min. Player Version   n/a 
 

The Music.groovoidGroup static method generates an array of Groovoid names, determined by a specified group prefix parameter.


SYNTAX    Music.groovoidGroup ( GroupPrefixSTR )

RETURN VALUE    GroovoidNamesStringARRAY

The Music.groovoidGroup static method generates an array, representing a subgroup of all the Groovoids available in the Beatnik Player's soundbank. The GroupPrefixSTR parameter will be used to determine which Groovoids make it into the resulting subgroup. Consider the following example...

List of Groovoids GroupPrefixSTR ResultARRAY
...
Hits-BlastOff
Hits-Kicker1
Hits-Kicker2
Hits-Kicker5
Hits-LudwigVan
Hits-Magic
Hits-MysteryChime
Hits-SportsOrganCharge
Hits-ZoomAndHit
...
Hits-Kicker Hits-Kicker1
Hits-Kicker2
Hits-Kicker5

In this example, all the Groovoids prefixed with "Hits-Kicker" are returned in the result array. Note that we haven't shown the full list of Groovoids above - just enough of a slice out of the list to serve as an illustration of how this method works (after all, the list of Groovoids is quite long).

SPECIAL VALUES
VARIATIONS
 Music.kwiklistToArray

 
 CATEGORY   Static Method 
 MODULE   Music Object Extension - Dynamic 
 Min. Player Version   n/a 
 

The Music.kwiklistToArray static method generates an array containing all the elements represented by the specified Kwiklist shorthand.

SYNTAX    Music.kwiklistToArray ( KwiklistSTR )

RETURN VALUE    StringARRAY

The Music.kwiklistToArray static method generates an array containing all the elements represented by the specified KwiklistSTR parameter. The Kwiklist shorthand syntax lets you express large lists of options in a much condensed form. For example, the following Groovoid names...

Hits-Kicker1
Hits-Kicker2
Hits-Kicker5
Hits-LudwigVan
Hits-Magic
Hits-MysteryChime
Hits-SportsOrganCharge
Hits-ZoomAndHit

...could be expressed as the following, using Kwiklist shorthand...

Hits-[Kicker[1|2|5]|LudwigVan|Magic|MysteryChime|SportsOrganCharge|ZoomAndHit]

In another example, the following list of filenames...

music/ambient/bliss.rmf
music/ambient/waterscape-full.rmf
music/ambient/waterscape-short.rmf
music/ambient/waterscape-groove.rmf
music/ambient/storm.rmf
music/techno/high.rmf
music/techno/pilon.rmf
music/techno/moonbuster.rmf

...could be expressed as the following, using Kwiklist shorthand...

music/[ambient/[bliss|waterscape-[full|short|groove]|storm]|techno/[high|pilon|moonbuster]].rmf

Using the Kwiklist syntax, redundancy is eliminated. If there is a common prefix to multiple items, then that common prefix need only be expressed once. Similarly, if there is a common suffix to multiple items, then that suffix need only be expressed once. In the Kwiklist syntax, square brackets are used to enclose a list of options, and options are separated by the pipe ("|") symbol.

Step by Step

Let's take the simplest example, the first example of a list of Groovoids, and go through the steps of creating a Kwiklist expression...

Hits-Kicker1
Hits-Kicker2
Hits-Kicker5
Hits-LudwigVan
Hits-Magic
Hits-MysteryChime
Hits-SportsOrganCharge
Hits-ZoomAndHit

You will notice from the list of Groovids that all the names are prefixed with "Hits-". So, we can take the common prefix out of all the items and begin our Kwiklist expression with this prefix, followed by square brackets to indicate that this prefix is to be added to the beginning of each of the options inside the square brackets. Inside the square brackets we will put the name of each Groovoid, minus the common prefix, as follows...

Hits-[Kicker1|Kicker2|Kicker5|LudwigVan|Magic|MysteryChime|SportsOrganCharge|ZoomAndHit]

Now, while this is somewhat optmized, there is a further optimization that can be made. You will notice that there are three items inside the square brackets that are prefixed with "Kicker" (highlighted in red). Because the Kwiklist syntax allows us to nest square brackets, we can express the three items "Kicker1", "Kicker2", and "Kicker5" more economically as just "Kicker[1|2|5]". And we can nest this expression inside the larger expression to form...

Hits-[Kicker[1|2|5]|LudwigVan|Magic|MysteryChime|SportsOrganCharge|ZoomAndHit]

 Music.random

 
 CATEGORY   Static Method 
 MODULE   Music Object Extension - Dynamic 
 Min. Player Version   n/a 
 

The Music.random static method generates a random integer within a specified range.

SYNTAX    Music.random ( RangeLowerLimitINT , RangeUpperLimitINT )

RETURN VALUE    RandomNumberINT

The Music.random static method generates a random integer within the range specified by the RangeLowerLimitINT and RangeUpperLimitINT parameters, inclusive of the RangeLowerLimitINT and RangeUpperLimitINT parameter values. This method is useful for randomizing values for parameters used in methods of the Music Object API. For example, Music.random (64,127) could be used to create a random pan value between center and full right, and Music.random (0,63) could be used to create a random pan value between full left and center. In another example, Music.random (Music.getNoteNumber ('C3'),Music.getNoteNumber ('C5')) could be used to randomly select a musical note number between C in the 3rd octave and C in the 5th octave.

VARIATIONS
 Music.randomFromGroup

 
 CATEGORY   Static Method 
 MODULE   Music Object Extension - Dynamic 
 Min. Player Version   n/a 
 

The Music.randomFromGroup static method randomly selects an item out of the specified group, as determined by a specified group prefix parameter.

SYNTAX    Music.randomFromGroup ( SourceARRAY , GroupPrefixSTR )

RETURN VALUE    RandomElementSTR

The Music.randomFromGroup method randomly selects an item out of a subgroup of the array specified by the SourceARRAY parameter. The source array should only contain string elements, unless a value of null or an empty string is specified for the GroupPrefixSTR parameter, or the variation of this method that does not take a GroupPrefixSTR parameter is being used (see the variations section further below). The subgroup that the random item is selected out of is determined by the GroupPrefixSTR parameter. For example, let's say we had an array defined as follows...

myFunkyFiles = new Array (
   'able-to-funk.wav',
   'functional-music.mid',
   'funk-monster.rmf',
   'funk-u-mutha-funka.wav',
   'funkadelic.rmf',
   'funky-chicken.mid',
   'get-down-and-funk.wav',
   'living-funkster.mid',
   'turn-up-the-funk.rmf'
);

...then the statement Music.randomFromGroup (myFunkyFiles,'funk') would randomly select an item out of the subgroup of items in the array myFunkyFiles that are prefixed with "funk". These items are highlighted in the array definition above.

This method can be quite useful in cases where one needs to randomly select music from a large catalog of files on a Web site. Consider, for example, the following array definition of a list of music files...

myMusicFiles = new Array (
   'music/ambient/bliss.rmf',
   'music/ambient/waterscape-full.rmf',
   'music/ambient/waterscape-short.rmf',
   'music/ambient/waterscape-groove.rmf',
   'music/ambient/storm.rmf',
   'music/rhythm/drummin-machine.rmf',
   'music/rhythm/unda-my-feet.rmf',
   'music/rhythm/conga-bonga.rmf',
   'music/rhythm/caught-in-a-snare.rmf',
   'music/rhythm/fatal-crash.rmf',
   'music/techno/high.rmf',
   'music/techno/pilon.rmf',
   'music/techno/moonbuster.rmf',
   'music/techno/power-spike.rmf'
);

You'll notice that the music files are arranged in a logical folder structure, according to their genre. Using the Music.randomFromGroup method, it now becomes quite easy to randomly select entries from this array based upon genre. For instance, the statement Music.randomFromGroup (myMusicFiles,'music/ambient/') would randomly select an ambient music file, and the statement Music.randomFromGroup (myMusicFiles,'music/techno/') would randomly select a techno music file.

SPECIAL VALUES
VARIATIONS
 Music.randomFromList

 
 CATEGORY   Static Method 
 MODULE   Music Object Extension - Dynamic 
 Min. Player Version   n/a 
 

The Music.randomFromList static method randomly selects an item out of a specified list of items.

SYNTAX    Music.randomFromList ( ListItem1 , ListItem2 , ListItem3 , ... , ListItemN )

RETURN VALUE    RandomItemANYTYPE

The Music.randomFromList method randomly selects an item from a list of items passed as parameters to the method. There is no limit to the number of items that can be specified when calling this method. Although the items in the list can be of mixed type, one will typically use the same type for all items in the parameter list. And in most cases, this will be the String type. For example, to play a randomly selected RMF file from a list of RMF files, one could use the statement myMusicObject.play (Music.randomFromList ('ambient.rmf', 'classical.rmf', 'house.rmf', 'jungle.rmf', 'lounge.rmf', 'modern-rock.rmf', 'sfx-medley.rmf', 'techno.rmf', 'trance.rmf')). Now, because all the files in this list are RMF files, the statement can be optimized as myMusicObject.play (Music.randomFromList ('ambient', 'classical', 'house', 'jungle', 'lounge', 'modern-rock', 'sfx-medley', 'techno', 'trance') + '.rmf'), since all the items in the list share the same suffix ".rmf".

In addition to using the Music.randomFromList method as a way of randomly selecting files to play, one can also randomize the selection of Groovoids, as in the statement myMusicObject.play (Music.randomFromList ('Hits-BlastOff', 'Hits-LudwigVan', 'Hits-ZoomAndHit', 'Fanfare-CorpSting1', 'Fanfare-Majesty', 'Misc-CashRegister', 'UI-TeletypeBurst2')). In another example using Groovoids, if one wished to randomly select from a specific subset of one of the groups of Groovoids, one could use a statement such as myMusicObject.play (Music.randomFromList ('Background-Clock', 'Background-Dubby', 'Background-Funky', 'Background-Latin', 'Background-StillWaiting')), which could further be simplified to myMusicObject.play ('Background-' + Music.randomFromList ('Clock', 'Dubby', 'Funky', 'Latin', 'StillWaiting')), since all of the Groovoids in this list share the same prefix.

It's not necessary to only use the Music.randomFromList method to select music files or Groovoids. If one wished to provide a dynamic interface to remixing a musical composition, one may wish to randomly mute / unmute a track that is randomly selected out of a list of tracks, as in the statement myMusicObject.setTracksMute (Music.randomFromList (5,9,15,16,19,23,27),'Toggle'). The tracks not included in this list could form the foundation of the musical groove, whereas the tracks in the list are embellishements which can be used in any combination, and with this statement can be randomly turned on and off to result in endless different combinations. Note that the setTracksMute method we are using in the statement is part of Music Object Extension - Groups.

VARIATIONS
 Music.randomGroovoid

 
 CATEGORY   Static Method 
 MODULE   Music Object Extension - Dynamic 
 Min. Player Version   n/a 
 

The Music.randomGroovoid static method randomly selects a Groovoid within a specified Groovoid group.

SYNTAX    Music.randomGroovoid ( GroovoidGroupSTR )

RETURN VALUE    GroovoidNameSTR

The Music.randomGroovoid method returns a String value, representing a Groovoid that has been randomly selected from the group of Groovoids specified by the GroovoidGroupSTR parameter. For instance, if one wished to play a randomly selected Groovoid from the "Background" group of Groovoids, one could use the statement myMusicObject.play (Music.randomGroovoid ('Background')). Similarly, to play a randomly selected Groovoid from the "Fanfare" group of Groovoids, one could use the statement myMusicObject.play (Music.randomGroovoid ('Fanfare')). One can even randomly select from variations of similar Groovoids within a Groovoid group. For example, the "UI" Groovoid group contains 17 variations of "click" Groovoids, named "UI-Click1", "UI-Click2", ... , "UI-Click17". One can easily randomly select a "click" Groovoid to play using the statement myMusicObject.play (Music.randomGroovoid ('UI-Click')).

VARIATIONS
Objects

 Music.Shuffler

 
 CATEGORY   Object Constructor 
 MODULE   Music Object Extension - Dynamic 
 Min. Player Version   n/a 
 

The Music.Shuffler object lets you generate integer numbers that are seemingly more random, using a "shuffling" algorithm.

SYNTAX    Music.Shuffler ( RandomRangeINT )

The Music.Shuffler object lets you generate random integer numbers that are seemingly more random than those generated using the Music.random static method. It does this by using an algorithm which is similar in principle to the process of shuffling a pack of cards.

Each card in a pack of cards is unique. If the pack is shuffled and then cards are drawn from the pack, one by one, until all the cards are exhausted, then no two cards that are drawn in a row will ever be the same. The only time there is some possibility of two cards in a row being the same is when the pack is reshuffled and the first card is drawn. It could happen that the first card drawn after shuffling is the same as the last card drawn from the previous shuffling of the pack. However, the odds of this happening are quite small. Compare this approach to generating random numbers to the Music.random method, where there is a good likelihood that the same number could be generated twice (and sometimes three or more times) in a row - even more so when the randomization range is smaller.

Constructor
Instance Methods

Following is a simple example of how the Music.Shuffler object could be used...

<HTML><HEAD><TITLE>Example Using Music.Playlist</TITLE></HEAD>
<BODY>

<SCRIPT SRC="music-object.js"></SCRIPT>
<SCRIPT SRC="music-object-x-dynamic.js"></SCRIPT>

<SCRIPT LANGUAGE=JavaScript><!-- //

myPlaylist = new Music.Playlist ();
music = new Music ();
music.stubEmbed ('stub.rmf');

// --></SCRIPT>

</BODY></HTML>

Static Properties

 Music.groovoids

 
 CATEGORY   Static Property 
 MODULE   Music Object Extension - Dynamic 
 Min. Player Version   n/a 
 File Types Supported   n/a 
 Type   array 
 Access   read only 
 

The Music.groovoids static property is an array of strings representing the names of all the Groovoids contained in the Beatnik Player soundbank.

This property is useful for randomly selecting or stepping through all the Groovoids that are available in the Beatnik soundbank. By dynamically selecting Groovoids to play using this property, one can help to ensure that sonified Web pages remain fresh for the end-user. The elements of this array reflect all the Groovoids in the Beatnik soundbank, as listed in the Appendix Beatnik Soundbank - Groovoids.